<template>
    <div class="Main1">
        <ul>
            <li v-for="(item,index) in carts" :key="index">
                <input type="checkbox" name="goods" :value="index">
                <span>[{{item.id}}]----------[{{item.title}}]-----------[{{item.price}}]-------------</span>
                <button @click="setCartBuyNumFn">加入购物车</button>
                </li>
        </ul>
    </div>
</template>

<script>
import {mapState, mapMutations, mapActions} from 'vuex'
export default {
    computed:{
        ...mapState({
            carts:state => state.carts.carts
        })
    },
    methods:{
        ...mapMutations({
            setCartBuyNumFn: 'carts/setCartBuyNum'
        }),
        ...mapActions({
            setCartsFn: 'carts/setCarts'
        })
    },
    created() {
        this.setCartsFn()
    }
}
</script>

<style scoped lang="scss">

</style>
